package xin.marcher.module.replenished.remote;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.inventory.api.InventoryServiceApi;
import xin.marcher.module.inventory.domain.response.WarningInventoryDTO;
import xin.marcher.module.replenished.converter.CompensationConverter;
import xin.marcher.module.replenished.exception.ReplenishedBizException;

import javax.annotation.Resource;

/**
 * 库存服务 API
 *
 * 
 */
@Component
public class InventoryRemote {

    @DubboReference(version = "1.0.0")
    private InventoryServiceApi inventoryServiceApi;

    @Resource
    private CompensationConverter compensationConverter;

    /**
     * 发送库存预警消息通知
     *
     * @param warningInventoryDTO
     */
    public void warningInventoryMessage(WarningInventoryDTO warningInventoryDTO) {
        JsonResult jsonResult = inventoryServiceApi.warningInventoryMessage(compensationConverter.converterRequest(warningInventoryDTO));
        if (!jsonResult.getSuccess()) {
            throw new ReplenishedBizException(jsonResult.getErrorCode(), jsonResult.getErrorMessage());
        }
    }


}
